package com.kaigejava.factorypattern.absFactory;

import com.kaigejava.factorypattern.method.PizzaAbstract;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by kaigejava on 2019/8/27.
 * 抽象工厂模式的披萨订单对象
 */
public class FactoryOrderPizza {
    /**
     * 声明一个AbsFactoryAbstract的属性
     */
    private IFactoryInterface factoryInterface;

    /**
     * 有参构造。将工厂对象通过有参传递
     */
    public FactoryOrderPizza ( IFactoryInterface factoryInterface){
        setFactory(factoryInterface);
    }

    public void setFactory( IFactoryInterface factoryInterface){
        PizzaAbstract pizzaAbstract = null;
        String ordertype;
        this.factoryInterface = factoryInterface;
        boolean flage = true;
        while (flage){
            ordertype = gettype();
            pizzaAbstract = factoryInterface.CreatePizza(ordertype);
            if (pizzaAbstract != null) {
                pizzaAbstract.prepare();
                pizzaAbstract.bake();
                pizzaAbstract.cut();
                pizzaAbstract.box();
            }else{
                System.out.println("**** 大爷你选择的不存在。请重新选择 greek pepper  over *****");
            }
        }
    }
    private String gettype() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(
                    System.in));
            System.out.println("input pizza type:");
            String str = strin.readLine();

            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }

}
